<?php 

define("hostname","http://palxi.khongmot.com/openid/");

function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

	@session_start();
	if(isset($_REQUEST['user']) && isset($_REQUEST['oauth_tok3n']) && isset($_REQUEST['oauth_token_secret']))
	{
			$params = "task=get_contact_list";
            $params .="&oauth_tok3n=". $_REQUEST['oauth_tok3n'];
            $params .="&oauth_token_secret=". $_REQUEST['oauth_token_secret'];   
            $params .="&user_id=".$_REQUEST['user'];      
			
			$params .="&screen_name=".$_REQUEST['screen_name'];   
			
			$url='https://api.twitter.com/1/users/show.json?screen_name='.$_REQUEST['screen_name']; //rss link for the twitter timeline
		
			
				
			
			if(isset($_SESSION['callback']))
			{
			$profile = http_build_query(json_decode(get_data($url)));
		
			$sUrlCallback = $_SESSION['callback'];
	
		unset($_SESSION['callback']);
		$security_token = $_SESSION['security_token'];
		$sForm =  <<<EOF
<form action="$sUrlCallback" method="POST" id="yahoo_connect">
	<input name="contact" type="hidden" value="$profile"/>
	<input name="service" type="hidden" value="2"/>
	<input type="hidden" value="$security_token" name="core[security_token]">
	<input name="get_success" type="hidden" value="1"/>
</form>
<script language="JavaScript" type="text/javascript">
	window.onload = submitYahoo;
	function submitYahoo()
	{
		document.getElementById('yahoo_connect').submit();
	}
</script>
EOF;

		echo $sForm;
}			
	}
	else{
		$link = hostname.'twitter/twitter.php?callbackUrl='.hostname.'twitter/';
		
		?>
		<script type="text/javascript">
			window.location.href = '<?php echo $link; ?>';
		</script>
		<?php
	}
?>
